package cn.kmsoft.spatialboot.controller;

import cn.kmsoft.stgeometry.util.GeoJsonQueryUtil;
import cn.kmsoft.stgeometry.util.Shapefile2GeoJson;
import cn.kmsoft.wololo.object.query.GeoJsonQuery;
import com.alibaba.fastjson.JSON;
import cn.kmsoft.common.ResponseStatus;
import cn.kmsoft.common.RestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;

@CrossOrigin
@RestController
@Api(description = "Hello服务调用", tags = "0-HelloController")
@RequestMapping(value = "/hello")
public class HelloController extends BaseController {
    private static final Log logger = LogFactory.getLog(HelloController.class);
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss-SSS");

    @ApiOperation(value = "test", notes = "test")
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public RestResponse test() {
        return RestResponse.succeed("hello test ok");
    }

    @ApiOperation(value = "geoJsonTest", notes = "获取默认geoJson对象测试")
    @RequestMapping(value = "/geoJsonTest", method= RequestMethod.GET)
    public RestResponse geoJsonTest(){
        RestResponse response = new RestResponse();

        //3-shp2geojson
        String shppath = this.testshpPath;
        //String shppath = "D:\\temp\\jssc\\500155梁平区\\01空间数据\\用地红线范围.shp";
        String geoJsonStr = Shapefile2GeoJson.shp2GeoJsonStr(shppath);
        //GeoJson geojson= Shapefile2GeoJson.shp2GeoJson(shppath);
        System.out.println();
        System.out.println(geoJsonStr);

        response.setResult(geoJsonStr);
        response.setCode(200);
        response.setStatus(ResponseStatus.SUCCEED.getMsg());
        response.setMsg("shp2GeoJsonStr success! ");
        response.setTimestamp(System.currentTimeMillis());

        return response;
    }


    @ApiOperation(value = "geoJsonQueryTest", notes = "获取默认geoJsonQuery对象测试")
    @RequestMapping(value = "/geoJsonQueryTest", method= RequestMethod.GET)
    public RestResponse geoJsonQueryTest(){
        RestResponse response = new RestResponse();

        //3-shp2geoquery
        int wkid = 4524;
        String shppath = this.testshpPath;
        //String shppath = "D:\\temp\\jssc\\500155梁平区\\01空间数据\\用地红线范围.shp";
        //String geoQueryStr = GeoJsonQueryUtil.shp2GeoQueryStr(shppath, wkid);
        GeoJsonQuery geoJsonQuery = GeoJsonQueryUtil.shp2GeoQuery(shppath, wkid);
        //GeoJsonQuery2 geoJsonQuery2 = GeoJsonQueryUtil.shp2GeoQuery2(shppath, wkid);
        System.out.println();
        System.out.println(JSON.toJSONString(geoJsonQuery));


        response.setResult(geoJsonQuery);
        response.setCode(200);
        response.setStatus(ResponseStatus.SUCCEED.getMsg());
        response.setMsg("shp2GeoQuery success! ");
        response.setTimestamp(System.currentTimeMillis());

        return response;
    }

}